const {
  Controller,
} = require('uni-cloud-router')

const ResponseUtil = require('../utils/Response.js')

module.exports = class TaskController extends Controller {
  async today() {
    const {
      ctx,
      service,
    } = this
    const {
      openId,
    } = ctx

    const { childId } = ctx.event

    if (!childId) {
      return ResponseUtil.error('子女不能为空')
    }

    return service.task.today({ openId, childId })
  }

  async list() {
    const {
      ctx,
      service,
    } = this
    const {
      openId,
    } = ctx

    return service.task.list({ openId })
  }

  add() {
    const {
      ctx,
      service,
    } = this
    const {
      openId,
    } = ctx

    return service.task.add({ openId, ...ctx.event })
  }

  remove() {
    const {
      ctx,
      service,
    } = this
    const {
      openId,
    } = ctx

    return service.task.remove({ openId, ...ctx.event })
  }

  change() {
    const {
      ctx,
      service,
    } = this

    return service.task.change({ ...ctx.event })
  }

  query() {
    const {
      ctx,
      service,
    } = this

    return service.task.query({ ...ctx.event })
  }
}
